# Pablo Rincon Crespo (C) 2009
# This code is published under the GPL 2 License Terms

from NMMirror import *
from NMListener import *
from NMConfig import *
import time, signal, os
from NMUtils import *

def handler(signum, frame):
	print 'SIGINT CAPTURED. Exiting...', signum
	exit(10)
signal.signal(signal.SIGINT, handler)

conf.verb=0

# Start server to receive encapsulated datagrams
(rhost,rport,iface_to)=readConfigListener()
if rhost is not None and rport is not None and iface_to is not None:
	listener=NMListener(rhost,int(rport),iface_to)
	listener.start()

mirrors=[]
# Get the mirrors (interface+filter+actions for matched packets)
mirrors=readConfigMirrors()

# Start threads
if mirrors is not None:
	for m in mirrors:
		m.start()

while 1:
	time.sleep(2)
#Net Mirror (c) 2009 Pablo Rincon Crespo
